/* helpers */
-static char *
-cst_trim_buff(char *buff)
-{
- char *c;
-
- c = buff + strlen(buff);
- while ((c >= buff) && ((unsigned char)*c <= ' ')) *c-- = '\0';
-
- c = buff;
- while ((*c != '\0') && ((unsigned char)*c <= ' ')) c++;
-
- return c;
-}
-
static void
cst_add_wpt(const route_head *track, waypoint *wpt)
{
char *cin = buff;
line++;
- cin = cst_trim_buff(buff);
+ cin = lrtrim(buff);
if (strlen(cin) == 0) continue;
if (strncmp(cin, "; ", 2) == 0) continue;
if (strncmp(cin + 2, "bitmap", 6) == 0)
{
- cin = cst_trim_buff(cin + 8);
+ cin = lrtrim(cin + 8);
if (*cin != '\0')
wpt->url = cst_make_url(cin);
}
while (NULL != fgets(buff, sizeof(buff), fin))
{
line++;
- cin = cst_trim_buff(buff);
+ cin = lrtrim(buff);
if (strcmp(cin + 2, "note") == 0)
{
fgets(buff, sizeof(buff), fin);
line++;
- cin = cst_trim_buff(buff);
+ cin = lrtrim(buff);
if (*cin != '\0')
wpt->notes = xstrdup(cin);
}
{
struct tm tm;
- pow = cst_trim_buff(++pow);
+ pow = lrtrim(++pow);
strptime(pow, "%Y %m %d %H:%M:%S", &tm);
wpt->creation_time = mkgmtime(&tm);
--- /dev/null
+/*
+
+ Support for Navigon Mobile Navigator Palm/OS pdb files,
+
+ Copyright (C) 2005 Olaf Klein, o.b.klein@t-online.de
+
+ This program is free software; you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation; either version 2 of the License, or
+ (at your option) any later version.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program; if not, write to the Free Software
+ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111 USA
+
+*/
+
+#include <ctype.h>
+#include <math.h>
+
+#include "defs.h"
+#include "coldsync/palm.h"
+#include "coldsync/pdb.h"
+#include "jeeps/gpsmath.h"
+
+#define MYNAME "nmn5"
+
+#define NMN5_MAGIC 0x766d6170 /* vmap */
+#define NMN5_ROUTE 0x49444154 /* IDAT */
+
+FILE *fd_in;
+static struct pdb *pdb_in;
+static char *fname_in;
+
+static arglist_t nmn5_args[] =
+{
+ {0, 0, 0, 0, 0 }
+};
+
+static double
+nmn5_to_degree(const int degx)
+{
+ int m, d, x;
+ double s, res;
+
+ d = degx / 100000;
+ x = degx % 100000;
+ m = x / 1000;
+ x = x % 1000;
+ s = (double)(x) / 10;
+
+ GPS_Math_DegMinSec_To_Deg(d, m, s, &res);
+
+ return res;
+}
+
+static void
+nmn5_read_data(const char *data, const size_t data_len)
+{
+ route_head *route;
+ char *cin = (char *)data;
+ char *cend = cin + data_len;
+
+ route = route_head_alloc();
+ route_add_head(route);
+
+ while (cin < cend)
+ {
+ char *lend;
+ int len;
+
+ lend = strchr(cin, '\x0A');
+ if (lend == NULL) break;
+
+ len = (lend - cin);
+ if (len > 0)
+ {
+ *lend = '\0';
+
+ if (case_ignore_strncmp(cin, "Wegname=", 8) == 0) /* This only works with the german release */
+ { /* test-data created with other releases are welcome */
+ cin += 8;
+ if (*cin != '\0')
+ route->rte_name = xstrdup(cin);
+ }
+ else if (case_ignore_strncmp(cin, "Fahrzeit=", 9) == 0)
+ {
+ }
+ else if (case_ignore_strncmp(cin, "Kosten=", 7) == 0)
+ {
+ }
+ else
+ {
+ char *buff, *comma;
+
+ /* now we are looking for a sequence like 0,1 NE (123456,654321) */
+
+ buff = xmalloc(strlen(cin) + 1); /* safe target space for sscanf( ... */
+
+ comma = cin;
+ while ((comma = strchr(comma, ',')))
+ {
+ int i, xlat, xlon;
+ waypoint *wpt;
+ char *cx;
+
+ comma++;
+
+ if (isdigit(*comma) == 0) continue;
+ if (isdigit(*(comma - 2)) == 0) continue;
+
+ if (4 != sscanf(comma, "%d %s (%d,%d)", &i, buff, &xlon, &xlat)) continue;
+ if (strchr("NESW", *buff) == NULL) continue; /* north, east, ... */
+
+ cx = comma - 2; /* go left over delta distance */
+ while (isdigit(*cx) != 0) *cx-- = '\0';
+ cin = lrtrim(cin);
+
+ for (i = 0; i < 2; i++) /* skip time and distance at start of line */
+ {
+ cin = strchr(cin, ' ');
+ cin = lrtrim(cin);
+ }
+
+ wpt = waypt_new();
+
+ wpt->latitude = nmn5_to_degree(xlat);
+ wpt->longitude = nmn5_to_degree(xlon);
+ wpt->description = xstrdup(cin);
+
+ cx = strchr(comma, ')'); /* find tailing notes after the coordinates */
+ if (cx != NULL)
+ {
+ char *tail = lrtrim(++cx);
+ if (*tail != '\0')
+ {
+ wpt->notes = xstrdup(tail);
+ }
+ }
+ if (*cin != '-')
+ waypt_add(waypt_dupe(wpt));
+
+ route_add_wpt(route, wpt);
+
+ break;
+ }
+ xfree(buff);
+ }
+
+ }
+ cin = lend + 1;
+ }
+}
+
+/* ============================================================================================
+ * &&& gobal callbacks &&&
+ * ----------------------------------------------------------------------------------------- */
+
+static void nmn5_rd_init(const char *fname)
+{
+ fname_in = xstrdup(fname);
+ fd_in = xfopen(fname, "rb", MYNAME);
+}
+
+static void nmn5_rd_deinit(void)
+{
+ fclose(fd_in);
+ xfree(fname_in);
+}
+
+static void nmn5_read(void)
+{
+ struct pdb_record *pdb_rec = NULL;
+
+
+ pdb_in = pdb_Read(fileno(fd_in));
+ is_fatal((pdb_in == NULL), "read failed.");
+
+ is_fatal((pdb_in->creator != NMN5_MAGIC), /* identify the database */
+ "Not a NMN5 pdb file (0x%08x).", pdb_in->creator);
+
+ is_fatal((pdb_in->version != 0), /* only version "0" currently seen and tested */
+ "This file is from an unsupported version (%d) of NMN5 and is unsupported.", pdb_in->version + 5);
+
+ is_fatal((pdb_in->type != NMN5_ROUTE),
+ "Unknown pdb data type (0x%08x).", pdb_in->type);
+
+ for (pdb_rec = pdb_in->rec_index.rec; pdb_rec; pdb_rec=pdb_rec->next)
+ {
+ char *data = (char *)pdb_rec->data;
+
+ if (be_read16(data) == 0)
+ nmn5_read_data(data + 3, pdb_rec->data_len - 3);
+ }
+ free_pdb(pdb_in);
+}
+
+/* ======================================================================================= */
+
+ff_vecs_t nmn5_vecs = {
+ ff_type_file,
+ { ff_cap_read, ff_cap_none, ff_cap_read }, /* real route + emulated waypoints */
+ nmn5_rd_init,
+ NULL,
+ nmn5_rd_deinit,
+ NULL,
+ nmn5_read,
+ NULL,
+ NULL,
+ nmn5_args,
+ CET_CHARSET_MS_ANSI, 1 /* CET-REVIEW */
+};